<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      size="mini"
      :data="list"
      border
      @selection-change="handleSelectionChange"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        width="55"/>
      <el-table-column
        prop="title"
        label="题目内容"
        width="450"
      />
      <el-table-column
        prop="options"
        label="题目选项"
      />
      <el-table-column
        prop="correctAnswer"
        label="答案"
        align="center"
        width="100"
      />
      <el-table-column
        prop="scoreValue"
        label="分值"
        align="center"
        width="50"
      />
      <el-table-column
        prop="typeName"
        label="类型"
        align="center"
        width="100"
      />
    </el-table>
    <div class="divid-page-class">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="pageTotal"
        @current-change="changeVal"
      />
    </div>
    <div>
      已选中{{selectedQuestionsItem}}
    </div>
  </div>
</template>

<script>
import { getQuestionList } from '@/api/question'
import { getTemplateList } from '@/api/template'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      currentPage: 1,
      pageSize: 10,
      pageTotal: 1,
      templateSelected: '',
      templateList: [],
      selectedQuestionsItem:[]
    }
  },
  created() {
    this.fetchData()
    this.getTemplate()
  },
  methods: {
    getTemplate() {
      getTemplateList().then(res => {
        this.templateList = res.data
      })
    },
    fetchData() {
      this.listLoading = true
      const params = {
        'current': this.currentPage,
        'size': this.pageSize
      }
      getQuestionList(params).then(res => {
        this.list = res.data.records
        this.pageTotal = res.data.total
        this.listLoading = false
      })
    },
    changeVal(val) {
      this.currentPage = val
      this.fetchData()
    },
    handleSelectionChange(val) {
      this.selectedQuestionsItem = val.length
    }
  }
}
</script>
